|
|
|
|
|
|
|
Figure 3.2.
Adding the Microsoft DAO 3.5
Reference to a Visual Basic Project. |
|
|
|
|
|
|
|
|
Now double-click the form to open the code window to the Form_Load event. You write the entire example in this procedure. |
|
|
|
|
|
|
|
|
When you open a Dynaset using Visual Basic code instead of using the data control, you must create two Visual Basic objects: a Database object and a Recordset object. Listing 3.1 shows how you create the objects in Visual Basic code. |
|
|
|
|
|
|
|
|
Listing 3.1. Creating a Database object and a Recordset object. |
|
|
|
|
|
|
|
|
Private Sub Form_Load()
'
' creating Dynaset-type recordsets
'
Dim db As Database ' the database object
Dim rs As Recordset ' the recordset object
'
End Sub |
|
|
|
|
|
|
|
|
You must initialize these objects with values before they can access data. This process is similar to setting the properties of the data control. To initialize the values, you first create two variables that correspond to the DatabaseName and RecordSource properties of the Visual Basic data control. The code sample in Listing 3.2 shows how it is done. |
|
|
|
|
| |
|
|
|
|
The code sample in Listing 3.2 uses the App.Path Visual Basic keywords. You can use the Path method of the App object to determine the drive letter and directory from which the program was launched. In |
|
|
|
|
|
|
|